FUNCTION ZFIFM_VIM_DETERM_PROC_108.
*"----------------------------------------------------------------------
*"*"本地接口：
*"  IMPORTING
*"     REFERENCE(IV_NO_UPDATE) TYPE  FLAG OPTIONAL
*"     REFERENCE(IV_PROC_TYPE) TYPE  /OPT/PROCESS_TYPE OPTIONAL
*"  EXPORTING
*"     REFERENCE(TAB_DSPMSG) TYPE  /OPT/STRUCT_MESSAGE_TABLE_T
*"  TABLES
*"      INDEX_ITEM TYPE  /OPT/CIDH_1ITEM_T
*"      MESSAGES STRUCTURE  /OPT/STRUCT_MESSAGE OPTIONAL
*"  CHANGING
*"     REFERENCE(INDEX_DATA) TYPE  /OPT/VIM_1HEAD OPTIONAL
*"  EXCEPTIONS
*"      CHECK_FAILED
*"----------------------------------------------------------------------
* Checks whether mandatory PO data are available in DP document.       *
* Does not add any data.                                               *
* Mandatory data are: EBELN, EBELP, MENGE, WRBTR, BSTME.               *
* Checks whether GR was done.                                          *
* Writes missing data info to error-structure.                         *
************************************************************************
  TYPE-POOLS : MRM.

* Begin of Insertion:VIMI-24216
  TYPES: BEGIN OF LTY_POITM_COND,
           EBELN TYPE EBELN,
           EBELP TYPE EBELP,
           KSCHL TYPE KSCHL,
           COUNT TYPE I,
         END OF   LTY_POITM_COND.
  DATA: LT_POITM_COND TYPE STANDARD TABLE OF LTY_POITM_COND,
        LW_POITM_COND TYPE LTY_POITM_COND,
        LT_ITEM1      TYPE TABLE OF /OPT/VIM_1ITEM,
        LV_EBELP      TYPE CHAR5.
* End   of Insertion:VIMI-24216

  DATA: LT_HEAD             TYPE TABLE OF /OPT/VIM_1HEAD,
        LS_HEAD             TYPE /OPT/VIM_1HEAD,
        LT_ITEM             TYPE TABLE OF /OPT/VIM_1ITEM WITH HEADER LINE,
        LT_PO_ITEM          TYPE TABLE OF /OPT/VIM_1ITEM,
        LS_PO_ITEM          TYPE /OPT/VIM_1ITEM,
        LS_ITEM             TYPE /OPT/VIM_1ITEM,
        LT_EKBE             TYPE TABLE OF EKBE,
        LS_EKBE             TYPE EKBE,
        LV_DEL_M            TYPE MENGE_D,
        LV_INV_M            TYPE MENGE_D,
        LV_REST_M           TYPE MENGE_D,
        LV_FAILED           TYPE C,
        LV_M_FOUND(1)       TYPE C,
        LS_T100             TYPE /OPT/VIM_T100,
        LS_BDCLOG           TYPE /OPT/VIM_MSG_T,
        LV_WEBRE            TYPE WEBRE,
        LV_BSTYP            TYPE BSTYP,                           "VIMI-16307B
        LV_PSTYP            TYPE PSTYP,
        LV_LEBRE            TYPE LEBRE,
        LV_PRODTYPE         TYPE PRODUCT_TYPE,                    "VIMI-28475
        LV_LFSNR            TYPE XBLNR,                           "VIMI-17732
        LV_NOQUAN           TYPE C,                               "VIMI-15143
        LT_ERROR            TYPE TABLE OF /OPT/VIM_MSG_T WITH HEADER LINE,
        LS_ERROR            TYPE /OPT/VIM_MSG_T,
        LT_T_ERROR          TYPE MRM_TAB_ERRPROT WITH HEADER LINE,
        LS_T_ERROR          TYPE LINE OF MRM_TAB_ERRPROT,
        LS_EX_ERROR         LIKE /OPT/STRUCT_MESSAGE,
        LS_EX_MESSAGE       LIKE /OPT/STRUCT_MESSAGE,
        LV_COUNT            TYPE I,
        LV_COUNT_STR(1)     TYPE C,
        LV_VAR1(50)         TYPE C,
        LV_VAR2(50)         TYPE C,
        LV_VAR3(50)         TYPE C,
        LV_VAR4(50)         TYPE C,
        LV_IND              TYPE NUMC3,
        LV_TEST(1)          TYPE C,
        SV_EBELN            TYPE EBELN,                           "VIMI-16082
        LT_HISTORY          TYPE TABLE OF BAPIEKBES,
        LS_HISTORY          TYPE BAPIEKBES,
        LT_POITEM           TYPE TABLE OF BAPIMEPOITEM,
        LS_POITEM           TYPE BAPIMEPOITEM,
* Begin of VIMI-24322/MVEMULA
        LT_POITEM_SA        TYPE TABLE OF BAPIEKPO,
        LS_POITEM_SA        TYPE BAPIEKPO,
* End of VIMI-24322/MVEMULA
        LV_DISABLE_GR_CHECK TYPE /PTGWFI/VALUE,             "VIMI-15071
        LV_ADDITIONAL_OPEN  TYPE XFELD. "VIMI-35892

* Begin of Change for VIMI-32512
  DATA:
    LT_EK08BN     TYPE TABLE OF EK08BN,
    LT_EK08BN_TMP TYPE TABLE OF EK08BN,
    LS_EK08BN_TMP TYPE EK08BN.
* End of Change for VIMI-32512

* Begin of Change for VIMI-34727
  DATA: LV_VENDOR     TYPE ELIFN,
        LV_COMMON_VEN TYPE FLAG,
        LS_HEADER_SL  TYPE BAPIEKKOL,
        LS_HEADER_PO  TYPE BAPIMEPOHEADER.
* End of Change for VIMI-34727
*Begin of VIMI-35147
  DATA: VALUE_MAX    LIKE DRSEG-WRBTR VALUE '99999999999.99',
        LV_PREIS     TYPE F,
        LV_PREIS_TMP TYPE F,
        LV_NETWR     TYPE BWERT,
        LV_MENGE     TYPE BSTMG.
*End of VIMI-35147

  DATA: BEGIN OF LT_T_ITEM OCCURS 0.
          INCLUDE STRUCTURE /OPT/VIM_1ITEM.
  DATA:  COMP_IND.
  DATA:  COMP_IND1.
  DATA:  END OF LT_T_ITEM.
  DATA: LV_STATE  TYPE DCDTELGET VALUE 'MXX'.       "VIMI-23774(PQ Scan issues)
  DATA: LS_T_ITEM LIKE LT_T_ITEM.

  CLEAR LV_FAILED.

*  " Add by roc.wang
  IF LINES( INDEX_ITEM[] ) > 100. "性能考虑 超过100行不再检查
    RETURN.
  ENDIF.
*  " End add

  SELECT SINGLE * FROM /OPT/VIM_T100 INTO LS_T100 WHERE DOCTYPE = INDEX_DATA-DOCTYPE.

* PO based doc type requires PO data
  IF LS_T100-INV_TYPE = 'LIV'.

* Logic Modules should have filled PO item data from PO/DN
*    If index_data-ebeln IS INITIAL.                    "no ebeln in header
    SELECT * FROM /OPT/VIM_1ITEM INTO TABLE LT_ITEM
                  WHERE DOCID = INDEX_DATA-DOCID.

    IF NOT LT_ITEM[] IS INITIAL.
      LOOP AT LT_ITEM INTO LS_ITEM.
* Begin of insert VIMI-15143
        CLEAR: LV_VAR1, LV_VAR2, LV_VAR3, LV_VAR4.
        CLEAR: LV_WEBRE, LV_PSTYP, LV_LEBRE, LV_NOQUAN.
* Start of INS VIMI-28475
*        SELECT SINGLE webre pstyp lebre FROM ekpo INTO (lv_webre,lv_pstyp,lv_lebre)
        SELECT SINGLE WEBRE
                      PSTYP
                      LEBRE
                      PRODUCTTYPE
                      NETWR            "VIMI-35147
                      MENGE            "VIMI-35147
                 FROM EKPO
                 INTO (LV_WEBRE,
                       LV_PSTYP,
                       LV_LEBRE,
                       LV_PRODTYPE,
                       LV_NETWR,         "VIMI-35147
                       LV_MENGE)         "VIMI-35147
* End of INS VIMI-28475
             WHERE EBELN = LS_ITEM-EBELN
             AND   EBELP = LS_ITEM-EBELP.
        IF SY-SUBRC = 0.
          IF ( LV_PSTYP EQ '9' OR LV_PSTYP EQ '1' )
              AND LV_LEBRE IS INITIAL.
            LV_NOQUAN = 'X'.
          ENDIF.
        ENDIF.
* End of insert VIMI-15143
*Begin of VIMI-35147
        IF LV_MENGE IS NOT INITIAL.
          LV_PREIS = LV_NETWR / LV_MENGE.
          LV_PREIS_TMP = LV_PREIS * LS_ITEM-MENGE.
        ENDIF.
        IF LV_PREIS_TMP > VALUE_MAX.
          LS_ERROR-MSGTYP = 'W'.
          LS_ERROR-MSGID  = '/OPT/VIM_701'.
          LS_ERROR-MSGNR  = '142'.
          APPEND LS_ERROR TO LT_ERROR.
        ENDIF.
*End of VIMI-35147
        IF     LS_ITEM-ALTERNATIVE <> 'A4'           "do not check G/L lines
           AND LS_ITEM-ALTERNATIVE <> 'A5'
           AND LV_COUNT < 6.                         "do not select error details for more than 5 lines
          IF LS_ITEM-COND_TYPE IS INITIAL.            "VIMI-15858 do not check planned costs
            IF   LS_ITEM-EBELN IS INITIAL
              OR LS_ITEM-EBELP IS INITIAL
* Begin of change VIMI-15143
*            OR ls_item-menge IS INITIAL
              OR ( LS_ITEM-MENGE IS INITIAL AND LV_NOQUAN IS INITIAL
                   AND LV_PSTYP NE '1' )                    "VIMI-37676
* End of change VIMI-15143
              OR ( LS_ITEM-WRBTR IS INITIAL
                   AND LV_PSTYP NE '1' )                    "VIMI-37676
* Begin of insert VIMI-17732
              OR ( LV_PSTYP = '0' AND LV_WEBRE = 'X' AND
* Start of CHG VIMI-28475
*                  ls_item-ref_doc IS INITIAL )
                   LS_ITEM-REF_DOC IS INITIAL AND LV_PRODTYPE NE '2' )
              OR ( LV_PSTYP = '0' AND LV_WEBRE = 'X' AND
                   LS_ITEM-SHEET_NO IS INITIAL AND LV_PRODTYPE = '2' )
              OR ( LV_PSTYP = 'A' AND LV_WEBRE = 'X' AND
                   LS_ITEM-SHEET_NO IS INITIAL AND LV_PRODTYPE = '2' )
* End of CHG VIMI-28475
              OR ( LV_PSTYP = '0' AND LV_WEBRE = 'X' AND
                  LS_ITEM-REF_DOC IS NOT INITIAL AND LS_ITEM-LFSNR IS INITIAL )
* End of insert VIMI-17732
* Begin of change VIMI-18382
*              OR ls_item-bstme IS INITIAL.
              OR ( LS_ITEM-BSTME IS INITIAL  AND LV_NOQUAN IS INITIAL ).
* End of change VIMI-18382
              LV_COUNT = LV_COUNT + 1.

              IF LS_ITEM-EBELN IS INITIAL.
                LV_VAR1 = 'EBELN'.
              ENDIF.
              IF LS_ITEM-EBELP IS INITIAL.
                IF LV_VAR1 IS INITIAL.
                  LV_VAR1 = 'EBELP'.
                ELSE.
                  LV_VAR2 = 'EBELP'.
                ENDIF.
              ENDIF.
              IF LS_ITEM-MENGE IS INITIAL.
                IF LV_VAR1 IS INITIAL.
                  LV_VAR1 = 'MENGE'.
                ELSE.
                  IF LV_VAR2 IS INITIAL.
                    LV_VAR2 = 'MENGE'.
                  ELSE.
                    LV_VAR3 = 'MENGE'.
                  ENDIF.
                ENDIF.
              ENDIF.
              IF LS_ITEM-WRBTR IS INITIAL.
                IF LV_VAR1 IS INITIAL.
                  LV_VAR1 = 'WRBTR'.
                ELSE.
                  IF LV_VAR2 IS INITIAL.
                    LV_VAR2 = 'WRBTR'.
                  ELSEIF LV_VAR3 IS INITIAL.
                    LV_VAR3 = 'WRBTR'.
                  ENDIF.
                ENDIF.
              ENDIF.
              IF LS_ITEM-BSTME IS INITIAL.
                IF LV_VAR1 IS INITIAL.
                  LV_VAR1 = 'BSTME'.
                ELSE.
                  IF LV_VAR2 IS INITIAL.
                    LV_VAR2 = 'BSTME'.
                  ELSEIF LV_VAR3 IS INITIAL.
                    LV_VAR3 = 'BSTME'.
                  ENDIF.
                ENDIF.
              ENDIF.
* Begin of insert VIMI-17732
* Start of CHG VIMI-28475
*              IF lv_pstyp = '0' AND lv_webre = 'X'.
*                IF ls_item-ref_doc IS INITIAL.
*                  IF lv_var1 IS INITIAL.
*                    lv_var1 = 'REF_DOC'.
*                  ELSE.
*                    IF lv_var2 IS INITIAL.
*                      lv_var2 = 'REF_DOC'.
*                    ELSEIF lv_var3 IS INITIAL.
*                      lv_var3 = 'REF_DOC'.
*                    ENDIF.
*                  ENDIF.
*              IF lv_pstyp = '0' AND lv_webre = 'X'.
              IF ( LV_PSTYP = '0' AND LV_WEBRE = 'X' ) OR
                 ( LV_PSTYP = 'A' AND LV_WEBRE = 'X' AND LV_PRODTYPE = '2' ).
*                  IF ls_item-ref_doc IS INITIAL.
                IF LS_ITEM-REF_DOC IS INITIAL AND LV_PRODTYPE NE '2'.
                  IF LV_VAR1 IS INITIAL.
                    LV_VAR1 = 'REF_DOC'.
                  ELSE.
                    IF LV_VAR2 IS INITIAL.
                      LV_VAR2 = 'REF_DOC'.
                    ELSEIF LV_VAR3 IS INITIAL.
                      LV_VAR3 = 'REF_DOC'.
                    ENDIF.
                  ENDIF.
                ELSEIF LS_ITEM-SHEET_NO IS INITIAL AND LV_PRODTYPE = '2'.
                  IF LV_VAR1 IS INITIAL.
                    LV_VAR1 = 'SHEET_NO'.
                  ELSE.
                    IF LV_VAR2 IS INITIAL.
                      LV_VAR2 = 'SHEET_NO'.
                    ELSEIF LV_VAR3 IS INITIAL.
                      LV_VAR3 = 'SHEET_NO'.
                    ENDIF.
                  ENDIF.
* End of CHG VIMI-28475
                ELSE.
                  SELECT SINGLE XBLNR INTO LV_LFSNR FROM EKBE WHERE EBELN = LS_ITEM-EBELN AND
                                                       EBELP = LS_ITEM-EBELP AND
                                                       LFBNR = LS_ITEM-REF_DOC AND
                                                       LFPOS = LS_ITEM-REF_DOC_IT AND
                                                       LFGJA = LS_ITEM-REF_DOC_YEAR.
                  IF SY-SUBRC = 0.
                    IF NOT LV_LFSNR IS INITIAL.
                      IF LV_VAR1 IS INITIAL.
                        LV_VAR1 = 'LFSNR'.
                      ELSE.
                        IF LV_VAR2 IS INITIAL.
                          LV_VAR2 = 'LFSNR'.
                        ELSEIF LV_VAR3 IS INITIAL.
                          LV_VAR3 = 'LFSNR'.
                        ENDIF.
                      ENDIF.
                    ELSE. " No delivery note number available
* Nothing to do, correct
                      IF LV_VAR1 IS INITIAL.
                        CONTINUE.
                      ENDIF.
                    ENDIF.
                  ENDIF.
                ENDIF.
              ENDIF.
* End of insert VIMI-17732

* BEGIN Insert VIMI-17507
              DATA: LT_STRUCCOMP_TABLE TYPE CL_ABAP_STRUCTDESCR=>COMPONENT_TABLE.
              DATA: LS_COMPONENT TYPE ABAP_COMPONENTDESCR.
              DATA: LS_DDIC_HEADER TYPE X030L.
              DATA: LO_STRUCDESCR TYPE REF TO CL_ABAP_STRUCTDESCR.
              DATA: LT_STRUCCOMP_TAB TYPE CL_ABAP_STRUCTDESCR=>COMPONENT_TABLE.
              DATA: LT_DD04T TYPE TABLE OF DD04T.
              DATA: LS_DD04T TYPE DD04T.
              DATA: ROLL_NAME TYPE DD04L-ROLLNAME.


*             Get components of structure
              LO_STRUCDESCR ?= CL_ABAP_STRUCTDESCR=>DESCRIBE_BY_NAME( '/OPT/VIM_1RITEM_DATA' ).
              LT_STRUCCOMP_TABLE = LO_STRUCDESCR->GET_COMPONENTS( ).

              LOOP AT LT_STRUCCOMP_TABLE INTO LS_COMPONENT.
                IF LS_COMPONENT-AS_INCLUDE IS INITIAL.
                  APPEND LS_COMPONENT TO LT_STRUCCOMP_TAB.
                ENDIF.
              ENDLOOP.

              IF LV_VAR1 IS NOT INITIAL.
                CLEAR LS_COMPONENT.
                READ TABLE LT_STRUCCOMP_TAB
                  WITH KEY NAME = LV_VAR1
                  INTO LS_COMPONENT.
                CLEAR LS_DDIC_HEADER.
                LS_DDIC_HEADER = LS_COMPONENT-TYPE->GET_DDIC_HEADER( ).
                CLEAR ROLL_NAME.
                MOVE LS_DDIC_HEADER-TABNAME TO ROLL_NAME.
                CLEAR LT_DD04T.
                CLEAR LS_DD04T.
                CALL FUNCTION 'DD_DTEL_GET'
                  EXPORTING
*                   get_state     = 'MXX'          "VIMI-23774(PQ Scan issues)
                    GET_STATE     = LV_STATE        "VIMI-23774(PQ Scan issues)
                    LANGU         = SY-LANGU
                    WITHTEXT      = 'X'
                    ROLL_NAME     = ROLL_NAME
                  TABLES
                    DD04T_TAB_A   = LT_DD04T
                  EXCEPTIONS
                    ILLEGAL_VALUE = 1
                    OTHERS        = 2.
                READ TABLE LT_DD04T INDEX 1 INTO LS_DD04T.
                IF LS_DD04T-SCRTEXT_S IS NOT INITIAL.
                  LV_VAR1 = LS_DD04T-SCRTEXT_S.
                ENDIF.
              ENDIF.

              IF LV_VAR2 IS NOT INITIAL.
                CLEAR LS_COMPONENT.
                READ TABLE LT_STRUCCOMP_TAB
                  WITH KEY NAME = LV_VAR2
                  INTO LS_COMPONENT.
                CLEAR LS_DDIC_HEADER.
                LS_DDIC_HEADER = LS_COMPONENT-TYPE->GET_DDIC_HEADER( ).
                CLEAR ROLL_NAME.
                MOVE LS_DDIC_HEADER-TABNAME TO ROLL_NAME.
                CLEAR LT_DD04T.
                CLEAR LS_DD04T.
                CALL FUNCTION 'DD_DTEL_GET'
                  EXPORTING
*                   get_state     = 'MXX'          "VIMI-23774(PQ Scan issues)
                    GET_STATE     = LV_STATE        "VIMI-23774(PQ Scan issues)
                    LANGU         = SY-LANGU
                    WITHTEXT      = 'X'
                    ROLL_NAME     = ROLL_NAME
                  TABLES
                    DD04T_TAB_A   = LT_DD04T
                  EXCEPTIONS
                    ILLEGAL_VALUE = 1
                    OTHERS        = 2.
                READ TABLE LT_DD04T INDEX 1 INTO LS_DD04T.
                IF LS_DD04T-SCRTEXT_S IS NOT INITIAL.
                  LV_VAR2 = LS_DD04T-SCRTEXT_S.
                ENDIF.
              ENDIF.

              IF LV_VAR3 IS NOT INITIAL.
                CLEAR LS_COMPONENT.
                READ TABLE LT_STRUCCOMP_TAB
                  WITH KEY NAME = LV_VAR3
                  INTO LS_COMPONENT.
                CLEAR LS_DDIC_HEADER.
                LS_DDIC_HEADER = LS_COMPONENT-TYPE->GET_DDIC_HEADER( ).
                CLEAR ROLL_NAME.
                MOVE LS_DDIC_HEADER-TABNAME TO ROLL_NAME.
                CLEAR LT_DD04T.
                CLEAR LS_DD04T.
                CALL FUNCTION 'DD_DTEL_GET'
                  EXPORTING
*                   get_state     = 'MXX'          "VIMI-23774(PQ Scan issues)
                    GET_STATE     = LV_STATE        "VIMI-23774(PQ Scan issues)
                    LANGU         = SY-LANGU
                    WITHTEXT      = 'X'
                    ROLL_NAME     = ROLL_NAME
                  TABLES
                    DD04T_TAB_A   = LT_DD04T
                  EXCEPTIONS
                    ILLEGAL_VALUE = 1
                    OTHERS        = 2.
                READ TABLE LT_DD04T INDEX 1 INTO LS_DD04T.
                IF LS_DD04T-SCRTEXT_S IS NOT INITIAL.
                  LV_VAR3 = LS_DD04T-SCRTEXT_S.
                ENDIF.
              ENDIF.
* END Insert VIMI-17507

              LV_VAR4 = LS_ITEM-ITEMID.
              LV_IND  = LV_COUNT.

              LS_ERROR-DOCID  = INDEX_DATA-DOCID.
              LS_ERROR-LOGINDEX = LV_IND.
              LS_ERROR-MSGTYP = 'W'.
              LS_ERROR-MSGID  = '/OPT/VIM_701'.
              LS_ERROR-MSGNR  = '047'.
              LS_ERROR-MSGV1  = LV_VAR1.
              LS_ERROR-MSGV2  = LV_VAR2.
              LS_ERROR-MSGV3  = LV_VAR3.
              LS_ERROR-MSGV4  = LV_VAR4.

              APPEND LS_ERROR TO LT_ERROR.

              LV_FAILED = 'X'.                     "mandatory data missing
            ELSE.
              APPEND LS_ITEM TO LT_PO_ITEM.
            ENDIF.                                 "fields empty
          ENDIF.                                            "VIMI-15858
          IF LV_COUNT = 6.                       "stop looping after 6 incomplete items
            EXIT.
          ENDIF.
        ENDIF.                                   "not for G/L lines
        CLEAR: LS_ERROR, LS_ITEM.
      ENDLOOP.
* Begin of Change for VIMI-34727
* Begin of Change for VIMI-32512
**C--Determine if PO/Scheduling agreement contains freight/additional cost lines
*      READ TABLE lt_item INTO ls_item INDEX 1. "#EC CI_NOORDER
*      CALL FUNCTION 'ME_READ_COND_INVOICE'
*        EXPORTING
*          i_ebeln = ls_item-ebeln
*          i_lifnr = ls_item-lifnr
*        TABLES
*          xek08bn = lt_ek08bn.
*
*      IF sy-subrc = 0 AND lt_ek08bn IS NOT INITIAL.
*        CLEAR: lt_ek08bn_tmp,ls_ek08bn_tmp.
*        LOOP AT lt_ek08bn INTO DATA(ls_ek08bn).
*
*          ls_ek08bn_tmp-bpwem = ls_ek08bn-bpwem.
*          ls_ek08bn_tmp-bprem = ls_ek08bn-bprem.
*          ls_ek08bn_tmp-bukrs = ls_ek08bn-bukrs.
*          ls_ek08bn_tmp-ebeln = ls_ek08bn-ebeln.
*          ls_ek08bn_tmp-ebelp = ls_ek08bn-ebelp.
*          COLLECT ls_ek08bn_tmp INTO lt_ek08bn_tmp.
*          CLEAR: ls_ek08bn_tmp,ls_ek08bn.
*        ENDLOOP.
*      ENDIF.
      LOOP AT LT_ITEM INTO LS_ITEM.
        IF SV_EBELN <> LS_ITEM-EBELN
          AND LS_ITEM-EBELN IS NOT INITIAL. "add by roc.wang for 添加了总账科目，VIM运行超级慢

          SV_EBELN = LS_ITEM-EBELN.

          CALL FUNCTION 'ME_READ_COND_INVOICE'
            EXPORTING
              I_EBELN = LS_ITEM-EBELN
              I_LIFNR = INDEX_DATA-LIFNR
            TABLES
              XEK08BN = LT_EK08BN.
          IF SY-SUBRC = 0 AND LT_EK08BN IS NOT INITIAL.
            LOOP AT LT_EK08BN INTO DATA(LS_EK08BN).

              LS_EK08BN_TMP-BPWEM = LS_EK08BN-BPWEM.
              LS_EK08BN_TMP-BPREM = LS_EK08BN-BPREM.
              LS_EK08BN_TMP-BUKRS = LS_EK08BN-BUKRS.
              LS_EK08BN_TMP-EBELN = LS_EK08BN-EBELN.
              LS_EK08BN_TMP-EBELP = LS_EK08BN-EBELP.
              LS_EK08BN_TMP-LIFNR = LS_EK08BN-LIFNR.
              LS_EK08BN_TMP-KSCHL = LS_EK08BN-KSCHL.
              COLLECT LS_EK08BN_TMP INTO LT_EK08BN_TMP.

              CLEAR: LS_EK08BN_TMP,LS_EK08BN.
            ENDLOOP.
          ENDIF.
        ENDIF.
      ENDLOOP.
      CLEAR SV_EBELN.
* End of Change for VIMI-34727

* no indication that net price is important - therefore commented
*      IF lv_failed IS INITIAL.
*        LOOP AT lt_po_item INTO ls_po_item.
*          SELECT SINGLE webre FROM ekpo INTO lv_webre
*              WHERE ebeln = ls_po_item-ebeln
*              AND   ebelp = ls_po_item-ebelp.
*          IF sy-subrc <> 0.
*            lv_failed = 'X'.
*          ELSEIF lv_webre = 'X'.                   "GR based invoice ver.
*            IF ls_po_item-netpr IS INITIAL.
*              lv_failed = 'X'.                     "mandatory data missing
*            ENDIF.
*          ENDIF.
*          CLEAR ls_po_item.
*        ENDLOOP.
*      ENDIF.


    ENDIF.
*    ENDIF.
  ENDIF.

* GR available?
  LOOP AT LT_ITEM INTO LS_ITEM.
    MOVE-CORRESPONDING LS_ITEM TO LS_T_ITEM.
    APPEND LS_T_ITEM TO LT_T_ITEM.
    CLEAR: LS_ITEM, LS_T_ITEM.
  ENDLOOP.
* If data is filled - is it correct?
  PERFORM DATA_CHECK IN PROGRAM /OPT/SAPLVIM_FG1 TABLES LT_T_ITEM LT_T_ERROR CHANGING LV_FAILED.

* GR available for GR based PO / Service No and item available?
  CLEAR LV_COUNT.

* begin VIMI-15071
  CALL FUNCTION '/OPT/VIM_READ_CONSTANT'
    EXPORTING
      PROD_CODE   = '005'
      PARAM_NAME  = 'DISABLE_GR_CHECK'
    IMPORTING
      PARAM_VALUE = LV_DISABLE_GR_CHECK
    EXCEPTIONS
      NOT_FOUND   = 1
      OTHERS      = 2.
  IF LV_DISABLE_GR_CHECK IS INITIAL.
* end VIMI-15071
    CLEAR SV_EBELN.                                         "VIMI-16082
    LOOP AT LT_ITEM INTO LS_ITEM.
      IF LV_COUNT < 6.                                     "error coll. limited to 5 more messages
        SELECT SINGLE WEBRE PSTYP LEBRE FROM EKPO INTO (LV_WEBRE,LV_PSTYP,LV_LEBRE)
             WHERE EBELN = LS_ITEM-EBELN
             AND   EBELP = LS_ITEM-EBELP.
        IF SY-SUBRC = 0.
          IF LV_WEBRE = 'X'.              "GR based invoice ver.
* Begin of insert VIMI-16082
            IF SV_EBELN <> LS_ITEM-EBELN.
              SV_EBELN = LS_ITEM-EBELN.
              REFRESH: LT_HISTORY, LT_POITEM.               "VIMI-16082
* End of insert VIMI-16082
* Begin of insert  VIMI-16307B
              SELECT SINGLE BSTYP FROM EKKO INTO LV_BSTYP
                         WHERE EBELN = LS_ITEM-EBELN.
* Begin of VIMI-22981
*              IF lv_bstyp <> 'F'
              IF LV_BSTYP EQ 'F' OR LV_BSTYP EQ 'L'.
              ELSE.
* End of VIMI-22981
                CONTINUE.
              ENDIF.
* End of insert  VIMI-16307B
*VIMI-18562: SAP Notes 2215852 in code scan is considered:
*Table POITEM with long/short material number is not used further
* Begin of VIMI-22981
              IF LV_BSTYP EQ 'L'.
                REFRESH: LT_POITEM_SA.
                CALL FUNCTION 'BAPI_PO_GETDETAIL'
                  EXPORTING
                    PURCHASEORDER          = LS_ITEM-EBELN
                    ITEMS                  = 'X'                         "VIMI-24322/MVEMULA
                    HISTORY                = 'X'
                  IMPORTING                                              "VIMI-34727
                    PO_HEADER              = LS_HEADER_SL                "VIMI-34727
                  TABLES
                    PO_ITEMS               = LT_POITEM_SA                "VIMI-24322/MVEMULA
                    PO_ITEM_HISTORY_TOTALS = LT_HISTORY.
* Begin of VIMI-24322/MVEMULA
                CLEAR: LS_POITEM_SA,
                       LS_POITEM.
                LOOP AT LT_POITEM_SA INTO LS_POITEM_SA.
                  MOVE-CORRESPONDING LS_POITEM_SA TO LS_POITEM.
                  APPEND LS_POITEM TO LT_POITEM.
                  CLEAR: LS_POITEM_SA,
                         LS_POITEM.
                ENDLOOP.
* End of VIMI-24322/MVEMULA
* Begin of Change for VIMI-34727
                LV_VENDOR = LS_HEADER_SL-VENDOR.
                CLEAR LS_HEADER_SL.
* End of Change for VIMI-34727
              ELSE.
* End of VIMI-22981
                CALL FUNCTION 'BAPI_PO_GETDETAIL1'
                  DESTINATION 'NONE' "VIMI-30728
                  EXPORTING
                    PURCHASEORDER    = LS_ITEM-EBELN
                  IMPORTING                              "VIMI-34727
                    POHEADER         = LS_HEADER_PO      "VIMI-34727
                  TABLES
                    POITEM           = LT_POITEM
                    POHISTORY_TOTALS = LT_HISTORY.
* Begin of Change for VIMI-34727
                LV_VENDOR = LS_HEADER_PO-VENDOR.
                CLEAR LS_HEADER_PO.
* End of Change for VIMI-34727
* Begin of VIMI-22981
              ENDIF.
* End of VIMI-22981
            ENDIF.                                          "VIMI-16082

* Begin of Change for VIMI-34727
            READ TABLE LT_EK08BN INTO LS_EK08BN WITH KEY EBELN = LS_ITEM-EBELN
                                                         EBELP = LS_ITEM-EBELP.
            IF SY-SUBRC = 0.
              DATA(LV_FREIGHT) = ABAP_TRUE.
*C-- Check whether Material line vendor and Freight Vendor are same
              IF LS_EK08BN-LIFNR = LV_VENDOR.
                LV_COMMON_VEN = ABAP_TRUE.
              ENDIF.
            ELSE.
              CLEAR LV_FREIGHT.
            ENDIF.
* End of Change for VIMI-34727

            READ TABLE LT_HISTORY INTO LS_HISTORY WITH KEY PO_ITEM = LS_ITEM-EBELP.
            IF SY-SUBRC = 0.
              IF LS_HISTORY-DELIV_QTY > 0.                  "delivered quantity > 0
* Begin of insert VIMI-21055
                READ TABLE LT_POITEM INTO LS_POITEM WITH KEY  PO_ITEM = LS_ITEM-EBELP.
                IF SY-SUBRC = 0 AND  LS_POITEM-ITEM_CAT EQ '9'
                             AND LV_LEBRE IS INITIAL.
* Quantity comparison is not required when item category = Service and
* Service-Based Invoice Verification indicator is initial
                ELSE.
* End of insert VIMI-21055
* Begin of insert VIMI-15745
* Consider credit memo
                  IF LS_ITEM-SHKZG = 'H'.
                    IF LS_HISTORY-IV_QTY < LS_ITEM-MENGE.
                      LV_IND = LV_IND + 1.
                      LV_COUNT = LV_COUNT + 1.
                      LV_FAILED = 'X'.
                      LV_VAR1 = LS_ITEM-ITEMID.
                      LS_ERROR-DOCID    = INDEX_DATA-DOCID.
                      LS_ERROR-LOGINDEX = LV_IND.
                      LS_ERROR-MSGTYP = 'W'.
                      LS_ERROR-MSGID  = '/OPT/VIM_701'.
                      LS_ERROR-MSGNR  = '087'.                  "Itemid &: quantity too high in credit memo
                      LS_ERROR-MSGV1  = LV_VAR1.
                      APPEND LS_ERROR TO LT_ERROR.
                    ENDIF.
                  ELSE.
* End of insert VIMI-15745
                    IF INDEX_DATA-VORGANG NE '3'.                   "VIMI_23766
* Begin of Change for VIMI-34727
*                      IF ls_history-deliv_qty <= ls_history-iv_qty.
* Begin of Change for VIMI-32512
*                        lv_ind = lv_ind + 1.
*                        lv_count = lv_count + 1.
*                        lv_failed = 'X'.
*                        lv_var1 = ls_item-ebelp.
*                        ls_error-docid    = index_data-docid.
*                        ls_error-logindex = lv_ind.
*                        ls_error-msgtyp = 'W'.
*                        ls_error-msgid  = 'VL'.
*                        ls_error-msgnr  = '444'.                  "already invoiced
*                        ls_error-msgv1  = lv_var1.
*                        APPEND ls_error TO lt_error.
*C--Check for Planned Delivery Cost lines
                      IF LV_FREIGHT = ABAP_TRUE.
                        CLEAR: LS_EK08BN,LV_FREIGHT.
* End of Change for VIMI-34727
                        TRY.
                            LS_EK08BN = VALUE #( LT_EK08BN_TMP[ EBELN = LS_ITEM-EBELN
                                                                EBELP = LS_ITEM-EBELP
                                                                KSCHL = LS_ITEM-COND_TYPE ] OPTIONAL ).
*                            IF ls_ek08bn IS NOT INITIAL AND ls_ek08bn-bpwem <= ls_ek08bn-bprem."VIMI-35892
                            IF LS_EK08BN-EBELN IS NOT INITIAL AND LS_EK08BN-BPWEM <= LS_EK08BN-BPREM."VIMI-35892
                              LV_IND = LV_IND + 1.
                              LV_COUNT = LV_COUNT + 1.
                              LV_FAILED = 'X'.
                              LV_VAR1 = LS_ITEM-EBELP.
                              LS_ERROR-DOCID    = INDEX_DATA-DOCID.
                              LS_ERROR-LOGINDEX = LV_IND.
                              LS_ERROR-MSGTYP = 'W'.
                              LS_ERROR-MSGID  = 'VL'.
                              LS_ERROR-MSGNR  = '444'.                  "already invoiced
                              LS_ERROR-MSGV1  = LV_VAR1.
                              APPEND LS_ERROR TO LT_ERROR.
                            ELSE.
*Begin - (VIMI-35892)
                              IF LS_EK08BN-EBELN IS NOT INITIAL.
                                IF LS_EK08BN-BPWEM >= LS_EK08BN-BPREM.
                                  LV_ADDITIONAL_OPEN = ABAP_TRUE.
                                ENDIF.
*End - (VIMI-35892)
                                CLEAR LV_REST_M.
                                LV_REST_M = LS_EK08BN-BPWEM - LS_EK08BN-BPREM.
                                IF  LV_REST_M  < LS_ITEM-MENGE.
                                  LV_IND = LV_IND + 1.
                                  LV_COUNT = LV_COUNT + 1.
                                  LV_FAILED = 'X'.
                                  LV_VAR1 = LS_ITEM-ITEMID.
                                  LS_ERROR-DOCID    = INDEX_DATA-DOCID.
                                  LS_ERROR-LOGINDEX = LV_IND.
                                  LS_ERROR-MSGTYP = 'W'.
                                  LS_ERROR-MSGID  = '/OPT/VIM_701'.
                                  LS_ERROR-MSGNR  = '084'.                  "Itemid &: delivered quantity smaller
                                  LS_ERROR-MSGV1  = LV_VAR1.
                                  APPEND LS_ERROR TO LT_ERROR.
                                ENDIF.
                              ENDIF."35892
                            ENDIF.

                            IF LV_COMMON_VEN = ABAP_TRUE.
*                              IF ls_history-deliv_qty <= ls_history-iv_qty."VIMI-35892
                              IF LS_HISTORY-DELIV_QTY <= LS_HISTORY-IV_QTY AND LV_ADDITIONAL_OPEN IS INITIAL."VIMI-35892
                                LV_IND = LV_IND + 1.
                                LV_COUNT = LV_COUNT + 1.
                                LV_FAILED = 'X'.
                                LV_VAR1 = LS_ITEM-EBELP.
                                LS_ERROR-DOCID    = INDEX_DATA-DOCID.
                                LS_ERROR-LOGINDEX = LV_IND.
                                LS_ERROR-MSGTYP = 'W'.
                                LS_ERROR-MSGID  = 'VL'.
                                LS_ERROR-MSGNR  = '444'.                  "already invoiced
                                LS_ERROR-MSGV1  = LV_VAR1.
                                APPEND LS_ERROR TO LT_ERROR..
                              ENDIF.
                              CLEAR LV_ADDITIONAL_OPEN."VIMI-35892
                              CLEAR LV_COMMON_VEN.
                            ELSE.
                              CLEAR LV_REST_M.
                              LV_REST_M = LS_HISTORY-DELIV_QTY - LS_HISTORY-IV_QTY.
                              IF  LV_REST_M  < LS_ITEM-MENGE.
                                LV_IND = LV_IND + 1.
                                LV_COUNT = LV_COUNT + 1.
                                LV_FAILED = 'X'.
                                LV_VAR1 = LS_ITEM-ITEMID.
                                LS_ERROR-DOCID    = INDEX_DATA-DOCID.
                                LS_ERROR-LOGINDEX = LV_IND.
                                LS_ERROR-MSGTYP = 'W'.
                                LS_ERROR-MSGID  = '/OPT/VIM_701'.
                                LS_ERROR-MSGNR  = '084'.                  "Itemid &: delivered quantity smaller
                                LS_ERROR-MSGV1  = LV_VAR1.
                                APPEND LS_ERROR TO LT_ERROR.
                              ENDIF.
                            ENDIF.
                          CATCH CX_SY_ITAB_LINE_NOT_FOUND.
* Begin of Change for VIMI-34727
*                            lv_ind = lv_ind + 1.
*                            lv_count = lv_count + 1.
*                            lv_failed = 'X'.
*                            lv_var1 = ls_item-ebelp.
*                            ls_error-docid    = index_data-docid.
*                            ls_error-logindex = lv_ind.
*                            ls_error-msgtyp = 'W'.
*                            ls_error-msgid  = 'VL'.
*                            ls_error-msgnr  = '444'.                  "already invoiced
*                            ls_error-msgv1  = lv_var1.
*                            APPEND ls_error TO lt_error.
* End of Change for VIMI-34727
                        ENDTRY.
* End of Change for VIMI-32512
* Begin of Change for VIMI-34727
                      ELSEIF LS_HISTORY-DELIV_QTY <= LS_HISTORY-IV_QTY.
                        LV_IND = LV_IND + 1.
                        LV_COUNT = LV_COUNT + 1.
                        LV_FAILED = 'X'.
                        LV_VAR1 = LS_ITEM-EBELP.
                        LS_ERROR-DOCID    = INDEX_DATA-DOCID.
                        LS_ERROR-LOGINDEX = LV_IND.
                        LS_ERROR-MSGTYP = 'W'.
                        LS_ERROR-MSGID  = 'VL'.
                        LS_ERROR-MSGNR  = '444'.                  "already invoiced
                        LS_ERROR-MSGV1  = LV_VAR1.
                        APPEND LS_ERROR TO LT_ERROR.
* End of Change for VIMI-34727
                      ELSE.
* Begin of change VIMI-15745
*                    IF ls_history-deliv_qty < ls_item-menge.
                        LV_REST_M = LS_HISTORY-DELIV_QTY - LS_HISTORY-IV_QTY.
                        IF  LV_REST_M  < LS_ITEM-MENGE.
* End of change VIMI-15745
                          LV_IND = LV_IND + 1.
                          LV_COUNT = LV_COUNT + 1.
                          LV_FAILED = 'X'.
                          LV_VAR1 = LS_ITEM-ITEMID.
                          LS_ERROR-DOCID    = INDEX_DATA-DOCID.
                          LS_ERROR-LOGINDEX = LV_IND.
                          LS_ERROR-MSGTYP = 'W'.
                          LS_ERROR-MSGID  = '/OPT/VIM_701'.
                          LS_ERROR-MSGNR  = '084'.                  "Itemid &: delivered quantity smaller
                          LS_ERROR-MSGV1  = LV_VAR1.
                          APPEND LS_ERROR TO LT_ERROR.
                        ENDIF.
                      ENDIF.
                    ENDIF.                                        "VIMI_23766
* Begin of insert VIMI-15745
                  ENDIF.
* End of insert VIMI-15745
* Begin of insert VIMI-21055
                ENDIF.
* End of insert VIMI-21055
              ELSE.
* Begin of insert VIMI-16307A
* Consider credit memo - accept it in case of CM without further checks
                IF LS_ITEM-SHKZG = 'H'.
* accept in case of CM without further checks
                ELSE.
* End of insert VIMI-16307A
                  LV_IND = LV_IND + 1.
                  LV_COUNT = LV_COUNT + 1.
                  LV_FAILED = 'X'.
                  LV_VAR1 = LS_ITEM-ITEMID.
                  LS_ERROR-DOCID    = INDEX_DATA-DOCID.
                  LS_ERROR-LOGINDEX = LV_IND.
                  LS_ERROR-MSGTYP = 'W'.
                  LS_ERROR-MSGID  = '/OPT/VIM_701'.
                  LS_ERROR-MSGNR  = '084'.                  "Itemid &: delivered quantity smaller
                  LS_ERROR-MSGV1  = LV_VAR1.
                  APPEND LS_ERROR TO LT_ERROR.
* Begin of insert VIMI-16307A
                ENDIF.
* End of insert VIMI-16307A

              ENDIF.
            ELSE.                                         "nothing delivered
              LV_IND = LV_IND + 1.
              LV_COUNT = LV_COUNT + 1.
              LV_FAILED = 'X'.
              LV_VAR1 = LS_ITEM-ITEMID.
              LS_ERROR-DOCID    = INDEX_DATA-DOCID.
              LS_ERROR-LOGINDEX = LV_IND.
              LS_ERROR-MSGTYP = 'W'.
              LS_ERROR-MSGID  = '/OPT/VIM_701'.
              LS_ERROR-MSGNR  = '084'.                  "Itemid &: delivered quantity smaller
              LS_ERROR-MSGV1  = LV_VAR1.
              APPEND LS_ERROR TO LT_ERROR.
            ENDIF.
          ENDIF.                                            "GR based
*          IF lv_pstyp = '9' AND lv_lebre = 'X'.             "Service based "VIMI-31689
          IF LV_PSTYP = '9' AND LV_LEBRE = 'X' AND LV_WEBRE = 'X'. "VIMI-31689
            IF LS_ITEM-SHEET_NO IS INITIAL.
              LV_IND = LV_IND + 1.
              LV_COUNT = LV_COUNT + 1.
              LV_FAILED = 'X'.
              LV_VAR1 = LS_ITEM-EBELN.
              LV_VAR2 = LS_ITEM-EBELP.
              LS_ERROR-DOCID    = INDEX_DATA-DOCID.
              LS_ERROR-LOGINDEX = LV_IND.
              LS_ERROR-MSGTYP = 'W'.
              LS_ERROR-MSGID  = 'OIO'.
              LS_ERROR-MSGNR  = '421'.                    "no service item found
              LS_ERROR-MSGV1  = LV_VAR1.
              LS_ERROR-MSGV2  = LV_VAR2.
              APPEND LS_ERROR TO LT_ERROR.
            ELSEIF LS_ITEM-SHEET_ITEM IS INITIAL.
              LV_IND = LV_IND + 1.
              LV_COUNT = LV_COUNT + 1.
              LV_FAILED = 'X'.
              LV_VAR1 = LS_ITEM-EBELN.
              LV_VAR2 = LS_ITEM-EBELP.
              LS_ERROR-DOCID    = INDEX_DATA-DOCID.
              LS_ERROR-LOGINDEX = LV_IND.
              LS_ERROR-MSGTYP = 'W'.
              LS_ERROR-MSGID  = 'OIO'.
              LS_ERROR-MSGNR  = '421'.                    "no service item found
              LS_ERROR-MSGV1  = LV_VAR1.
              LS_ERROR-MSGV2  = LV_VAR2.
              APPEND LS_ERROR TO LT_ERROR.
            ENDIF.
          ENDIF.
        ENDIF.                                            "found in ekpo
      ELSE.
        EXIT.
      ENDIF.                                              "limit to 5 problem item loops
      CLEAR: LS_ITEM, LS_ERROR, LV_VAR1, LV_VAR2, LV_VAR3.
    ENDLOOP.
  ENDIF.                                                    "VIMI-15071

  DELETE ADJACENT DUPLICATES FROM LT_ERROR COMPARING DOCID MSGTYP MSGID MSGNR MSGV1 MSGV2. "VIMI-34727

* Begin of Insertion:VIMI-24216
  IF LT_ITEM[] IS NOT INITIAL.
    APPEND LINES OF LT_ITEM TO LT_ITEM1[].
    SORT LT_ITEM1[] BY DOCID ITEMID BUKRS EBELN EBELP.
    DELETE LT_ITEM1 WHERE COND_TYPE EQ SPACE.
    LOOP AT LT_ITEM1 INTO LS_ITEM WHERE LIFNR IS INITIAL.
      LW_POITM_COND-EBELN = LS_ITEM-EBELN.
      LW_POITM_COND-EBELP = LS_ITEM-EBELP.
      LW_POITM_COND-KSCHL = LS_ITEM-COND_TYPE.
      LW_POITM_COND-COUNT = LW_POITM_COND-COUNT + 1.
      COLLECT LW_POITM_COND INTO LT_POITM_COND.
      CLEAR:LW_POITM_COND.
    ENDLOOP.

    LOOP AT LT_POITM_COND INTO LW_POITM_COND WHERE COUNT GT 1.
      LV_FAILED = 'X'.
      LS_ERROR-DOCID = INDEX_DATA-DOCID.
      LS_ERROR-MSGID = '/OPT/VIM_101'.
      LS_ERROR-MSGTYP = 'E'.
      LS_ERROR-MSGNR = '084'.
      LS_ERROR-MSGV1 = LW_POITM_COND-EBELN.
      WRITE LW_POITM_COND-EBELP TO LV_EBELP NO-ZERO.
      CONDENSE LV_EBELP.
      LS_ERROR-MSGV2 = LV_EBELP.
      LS_ERROR-MSGV3 = LW_POITM_COND-KSCHL.
      APPEND LS_ERROR TO LT_ERROR.
      CLEAR: LV_EBELP.
    ENDLOOP.
  ENDIF.
* End   of Insertion:VIMI-24216

*
  IF NOT LT_T_ERROR[] IS INITIAL.
    LV_FAILED = 'X'.
    LOOP AT LT_T_ERROR INTO LS_T_ERROR.
      LV_IND = LV_COUNT + 1.
      LS_ERROR-DOCID    = INDEX_DATA-DOCID.
      LS_ERROR-PTYPE    = IV_PROC_TYPE.
      LS_ERROR-LOGINDEX = LV_IND.
      LS_ERROR-MSGTYP   = LS_T_ERROR-MSGTY.
      LS_ERROR-MSGID    = LS_T_ERROR-MSGID.
      LS_ERROR-MSGNR    = LS_T_ERROR-MSGNO.
      LS_ERROR-MSGV1    = LS_T_ERROR-MSGV1.
      LS_ERROR-MSGV2    = LS_T_ERROR-MSGV2.
      LS_ERROR-MSGV3    = LS_T_ERROR-MSGV3.
      LS_ERROR-MSGV4    = LS_T_ERROR-MSGV4.
      APPEND LS_ERROR TO LT_ERROR.
      CLEAR LS_ERROR.
    ENDLOOP.
  ENDIF.

  IF NOT LT_ERROR[] IS INITIAL.
    IF LV_TEST IS INITIAL.
      LS_BDCLOG-DOCID   = INDEX_DATA-DOCID.
      LS_BDCLOG-PTYPE    = IV_PROC_TYPE.
      LOOP AT LT_ERROR.
*        ls_bdclog-logindex = sy-tabix.
*        ls_bdclog-msgtyp   = lt_error-msgtyp.
*        ls_bdclog-msgid    = lt_error-msgid.
*        ls_bdclog-msgnr    = lt_error-msgnr.
*        ls_bdclog-msgv1    = lt_error-msgv1.
*        ls_bdclog-msgv2    = lt_error-msgv2.
*        ls_bdclog-msgv3    = lt_error-msgv3.
*        ls_bdclog-msgv4    = lt_error-msgv4.
*        INSERT /opt/vim_msg_t FROM ls_bdclog.
        MOVE-CORRESPONDING LT_ERROR TO LS_EX_ERROR.
        LS_EX_ERROR-PROC_TYPE = IV_PROC_TYPE.
        APPEND LS_EX_ERROR TO TAB_DSPMSG.
        CLEAR LS_EX_ERROR.
      ENDLOOP.
    ENDIF.
  ENDIF.

  IF LV_FAILED = 'X'.
    RAISE CHECK_FAILED.
  ENDIF.

ENDFUNCTION.
